<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" pageEncoding="UTF-8" buffer="64kb"%>
<%@ include file="/pages/safeai/jsp/common/taglibs.jsp"%>
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>收货信息</title>
		<link href="${ctx}/css/style.css" rel="stylesheet" type="text/css" />
		<script type='text/javascript' src='${ctx}/js/validate.js'></script>
		<script type='text/javascript' src='${ctx}/js/Ajax.js'></script>
		<script type='text/javascript' src='${ctx}/dwr/engine.js'></script>
		<script type='text/javascript' src='${ctx}/dwr/util.js'></script>
		
		<script language="JavaScript" src="${ctx}/js/jquery.js"></script>
		<script language="JavaScript" src="${ctx}/js/filter.js"></script>
		<script language="JavaScript" src="${ctx}/js/json2.js"></script>
	</head>
	<body>
		<div class="bg">
		  <div class="bg_inside">
		<div class="head">
			<c:import url="/pages/safeai/jsp/shop/header.jsp"></c:import>
		</div>
		<c:import url="/front/userinfo.do?method=myRayi"></c:import>
		
		<div class="user_order_content"> 
		<div  class="user_order_content_top"><img src="../images/user_order_content_top.jpg" /></div>
		<div class="user_order_content_center">
		
		
		<ul style="border-bottom:1px dashed #ddd;padding-bottom:10px">
			<logic:notPresent name="historylist">
				<li style=" background-image:url(../images/title_letter_icon.jpg); background-position:left center; background-repeat:no-repeat;padding:5px 0px 0px 15px;margin-bottom:5px;line-height:15px;color:#5a3e2e">收货信息</li><li>你尚未添加收货信息，请添加<a href="" ><font class="orange">新的收货信息</font></a>，您最多可添加3个收货地址</li>
				<div id="add">
			</logic:notPresent>
			<logic:present name="historylist">
				<div id="add" style="display:none">
			</logic:present>
			
			<form action="${ctx}/front/userinfo.do" method="post" name="userInfoForm">
				<input type="hidden" name="method" id="method" value="addHistoryAddr"/>
				<input type="hidden" name="pwm.historyId" id="historyId"/>
				<li>收 货 人：<label>  <input name="pwm.hconsignee" id="hconsignee" type="text"  />  </label></li>
				<li>省　　份： <label><select name="pwm.province" id="provinces"></select></label>　<label><select name="pwm.rcity" id="citys"></select></label>　<label><select name="pwm.town" id="villages"></select></label></li>
				<li>地　　址： <label>  <input name="pwm.haddress" id="haddress" type="text" />  </label></li>
				<li>邮　　编： <label>  <input name="pwm.hpostcode" id="hpostcode" maxlength="6" type="text" />  </label></li>
				<li>联系电话： <label>  <input name="pwm.hphone" id="hphone"  type="text" maxlength="16"/>  </label></li>
				<li>手　　机： <label>  <input name="pwm.hmobile" id="hmobile"  type="text" maxlength="11"/>  </label> 我们会用免费短信及时通知您发货信息，如果不填，则不发送该信息。</li>
				<li>电子邮件： <label>  <input name="pwm.hemail" id="hemail"  type="text" />  </label></li>
				<li style="padding-left:65px;width:300px"><a href="#" onclick="check();" class="reg_button ">提交信息</a></li>
			</form>
			</div>
		</ul>
		
		<ul style="border-bottom:1px dashed #ddd;padding-bottom:10px">
			<logic:present name="historylist">
				<logic:iterate id="history" name="historylist">
					<input type="hidden" id="historyId" value="${history.id}" />	
					<li style=" background-image:url(../images/title_letter_icon.jpg); background-position:left center; background-repeat:no-repeat;padding:5px 0px 0px 15px;margin-bottom:5px;line-height:15px;color:#5a3e2e">收货信息</li>
					<li>收 货 人：${history.consignee}</li>
					<li>省　　份：${history.province}&nbsp;${history.city}&nbsp;${history.village}  </li>
					<li>地　　址：${history.address}</li>
					<li>邮　　编：${history.postcode}</li>
					<li>联系电话：${history.phone}</li>
					<li>手　　机：${history.mobile}</li>
					<li>电子邮件：${history.email}</li>
					<li style="padding-left:65px;width:300px"><a href="#" id="tou" onclick="toUpdate('${history.oid}','${history.consignee}','${history.province}','${history.city}','${history.village}','${history.address}','${history.postcode}','${history.phone}','${history.mobile}','${history.email}');" class="reg_button ">修改信息</a>　</li>
				</logic:iterate>
			</logic:present>
		</ul>
		
		<ul style="border-bottom:1px dashed #ddd;padding-bottom:10px"><li>如果您有新的收货地址，<a href="#" onclick="toAdd();"><font class="orange">请添加新的收货地址</font></a></li></ul>
		</div>
		<div  class="user_order_content_bottom"><img src="../images/user_order_content_bottom.jpg" /></div>
		</div>
		</div>
		
		<div style="margin-top:10px;*+margin-top:20px"><%@ include file="/user/commonProblem.jsp"%></div>
		<div class="bottom">
	<%@ include file="/pages/safeai/jsp/shop/bottom.jsp"%>	
	<div class="clearAll"></div>
</div>
	</body>
</html>

<script language="javascript">
	 function toAdd(){ 
   			document.getElementById("add").style.display=""; 
   			
   			document.getElementById("historyId").value = "";
   			document.getElementById("hconsignee").value = "";
  			document.getElementById("haddress").value = "";
  			document.getElementById("hpostcode").value = "";
  			document.getElementById("hphone").value = "";
  			document.getElementById("hmobile").value = "";
  			document.getElementById("hemail").value = "";
   } 


   function toUpdate(v1,v2,v3,v4,v5,v6,v7,v8,v9,v10){
   			document.getElementById("add").style.display=""; 
   			
   			document.getElementById("historyId").value = v1;
   			document.getElementById("hconsignee").value = v2;
   			
   			var provinceOptions = document.getElementById("provinces");
			var cityOptions = document.getElementById("citys");
			var villageOptions = document.getElementById("villages");
			
			var itemCount1 = provinceOptions.options.length; 
			
			for (var i=0;i <itemCount1;i++){ 
				if (provinceOptions.options[i].value == v3){	       
			        provinceOptions.options[i].selected = true;
			      } 
		    } 
		    
		    provinceOptions.onchange();
		    var itemCount = cityOptions.options.length;
			
		   
			for (var j=0;j <itemCount;j++){  
				if (cityOptions.options[j].value == v4){	        
			        cityOptions.options[j].selected = true;
			    } 
		    } 
		    
		    cityOptions.onchange();
		    var itemCount2 = villageOptions.options.length;
		    
			for (var z=0;z <itemCount2;z++){ 
				if (villageOptions.options[z].value == v5) {	       
			        villageOptions.options[z].selected = true;
			    } 
		    } 
	   		
  
  			document.getElementById("haddress").value = v6;
  			document.getElementById("hpostcode").value = v7;
  			document.getElementById("hphone").value = v8;
  			document.getElementById("hmobile").value = v9;
  			document.getElementById("hemail").value = v10;
   } 

   function check(){
        var form = document.getElementsByTagName("form")[1];

        var hconsignee = document.getElementById("hconsignee").value;
        var haddress = document.getElementById("haddress").value;
        var hpostcode = document.getElementById("hpostcode").value;
        var hphone = document.getElementById("hphone").value;
        var hmobile = document.getElementById("hmobile").value;
        var hemail = document.getElementById("hemail").value;
         
        if(hconsignee==null || hconsignee==""){
       		alert("收货人姓名不能为空!");
       		document.getElementById("hconsignee").focus();
			return;
        }else{
        	var pattern=/([!\@\#\$%^&*()+|\\{}:;?<>`])+/; 
				if((pattern.test(hconsignee))) { 
				alert("收货人姓名不能包含特殊字符!"); 
				return false; 
			} 
        	if(hconsignee.length>255){
        		alert("收货人姓名长度不能超过255个字符!");
        		return false;
        	}
        }
        //省
       var provinces=document.getElementById("provinces").value;
       //市
       var citys=document.getElementById("citys").value;
       //区
       var villages=document.getElementById("villages").value;
       if(provinces=="请选择"){
       		alert("省份不能为空!");
       		return false;
       }
       if(citys=="请选择"){
       		alert("城市不能为空!");
       		return false;
       }
       if(villages=="请选择"){
       		alert("区或县不能为空!");
       		return false;
       }
         if(haddress==null || haddress==""){
       		alert("收货人地址不能为空!");
       		document.getElementById("haddress").focus();
			return;
        }else{
        	var pattern=/([!\@\#\$%^&*()+|\\{}:;?<>`])+/; 
				if((pattern.test(haddress))) { 
				alert("收货人地址不能包含特殊字符!"); 
				return false; 
			}
        	if(haddress.length>255){
				alert("收货人地址不能超过255个字符！");
				return false;        	
        	}
        }
         
        if(hemail!=null && hemail!=""){
				var pattern =/^[a-zA-Z0-9_\-.]{1,}@[a-zA-Z0-9_\-]{1,}\.[a-zA-Z0-9_\-.]{1,}$/;
				if(!pattern.exec(hemail)){
					alert("请输入正确的邮箱地址!");
					return false;
				}
				if(hemail.length>60){
					alert("邮箱的最大长度为60个字符!");
					return false;
				}
	      }else{
	        alert("电子邮件不能为空!");
	        document.getElementById("hemail").focus();
	        return false;
	      }
		
		if(hpostcode!=null && hpostcode!=""){
			if(/^[0-9]{6}$/.test(hpostcode)){
			}else{
				alert('请输入正确的邮政编码，如160000');
				document.getElementById("hpostcode").focus();
				return;
			}
			}else{
	        alert("邮编不能为空!");
	        document.getElementById("hpostcode").focus();
	        return;
	      }

		//if(hmobile !=null && hmobile !=''){
		//	if(/^(?:13\d|15\d|18\d)-?\d{5}(\d{3}|\*{3})$/.test(hmobile)){
		//	}else{
		//		alert('请输入正确的手机号码,如13501284888或15811445345');
		//		document.getElementById("hmobile").focus();
		//		return ;
		//	}
		//}	
		if(hmobile == null || hmobile == ""){
			document.getElementById("hmobile").focus();
			alert("请输入您的手机号码!");
			return false;
		}else{
			if(hmobile.length!=11){
				alert("手机号码长度不对！");
				return false;
			}
		}
		if(hphone !=null && hphone != ''){
			if(/^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/.test(hphone)){}else{
				document.getElementById("hphone").focus();
				alert('请输入正确的固定电话,如010-63458858或010-63458858-025');
      			return;
			}
		}
        form.submit();
   }
   
   window.onload=function(){//onload start    
    //************************城市级联开始**********************************
       //省
       var provinces=document.getElementById("provinces");
       //市
       var citys=document.getElementById("citys");
       //区
       var villages=document.getElementById("villages");
       //邮编
       //var zip=document.getElementById("hpostcode");
       
       getProvinces();
       getCitys();
       getVillages();
       //getZip();
       provinces.onchange=function(){
           getCitys();
           getVillages(); 
          
       }
       citys.onchange=function(){
           getVillages();
           
       }
       villages.onchange=function(){
           getZip();
       }
       
       
    }//onload end
    function getProvinces(){
        var ajax=new Ajax();
        ajax.ajaxRequest("${ctx}/order/cityOreder.do","method=getAllProvince","get",backProvince);
    }
    
    function backProvince(str){
        var list=str.split(",");
        DWRUtil.removeAllOptions("provinces");
	    DWRUtil.addOptions("provinces", list);
    }
    
    function getCitys(){
        var ajax=new Ajax();
        var provinces=document.getElementById("provinces");
        var provinceName=provinces.options[provinces.selectedIndex].value;
        ajax.ajaxRequest("${ctx}/order/cityOreder.do","method=getCitys&provinceName="+encodeURI(provinceName),'get',backCity);
    }
    
    function backCity(str){
        var list=str.split(",");
        DWRUtil.removeAllOptions("citys");
	    DWRUtil.addOptions("citys", list);
    }
    
    function getVillages(){
    var ajax=new Ajax();
        var provinces=document.getElementById("provinces");
        var citys=document.getElementById("citys");
        var provinceName=provinces.options[provinces.selectedIndex].value;
        var cityName=citys.options[citys.selectedIndex].value;
        ajax.ajaxRequest("${ctx}/order/cityOreder.do","method=getVillages&provinceName="+encodeURI(provinceName)+"&cityName="+encodeURI(cityName),'get',backVillage);
    }
    
    function backVillage(str){
        var list=str.split(",");
        DWRUtil.removeAllOptions("villages");
	    DWRUtil.addOptions("villages", list);
    }
    
	function getZip(){
	    var ajax=new Ajax();
        var provinces=document.getElementById("provinces");
        var citys=document.getElementById("citys");
        var villages=document.getElementById("villages");
        
        var provinceName=provinces.options[provinces.selectedIndex].value;
        var cityName=citys.options[citys.selectedIndex].value;
        var villagesName=villages.options[villages.selectedIndex].value;
        
        ajax.ajaxRequest("${ctx}/order/cityOreder.do","method=getZip&provinceName="+encodeURI(provinceName)+"&cityName="+encodeURI(cityName)+"&villageName="+encodeURI(villagesName),'get',backZip);
    }
    
    function backZip(str){
       document.getElementById("hpostcode").value = str;
    }
    //************************城市级联结束**********************************
</script>